package cate.game.role.pvp.guildwar.msg;

import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgOutput;
import cate.game.client.msg.id.MsgIdBGuildWar;
import cate.game.pvp.guildwar.data.GWGuildProfile;
import cate.game.pvp.guildwar.data.GuildWar;
import cate.game.pvp.guildwar.data.GuildWarFightSide;
import cate.game.pvp.guildwar.data.GuildWarPt;
import cate.game.role.pvp.guildwar.vo.GuildWarPtVO;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

@ClientMsg(title = "公会战-战场数据 返回")
public class GuildWarFieldResp implements MsgOutput {

    @NoteField(value = "队伍",detail = "1是我方 2是敌方")
    public byte team;

    @NoteField("公会简要信息")
    public GWGuildProfile profile;

    @NoteField("总星星数")
    public int totalStar;

    @NoteField("当前buff等级")
    public int buffLevel;

    @NoteField("据点列表")
    public List<GuildWarPtVO> ptList = new ArrayList<>();

    public GuildWarFieldResp(byte team, GuildWar data) {
        this.team = team;
        GuildWarFightSide fightSide = data.field.getSide(team);
        if (fightSide != null) {
            this.profile = fightSide.profile;
            this.buffLevel = fightSide.buffLevel;
            this.totalStar = fightSide.totalStar();
            for (GuildWarPt value : fightSide.ptMap.values()) {
                this.ptList.add(GuildWarPtVO.of(value));
            }
            ptList.sort(Comparator.comparing(p -> p.ptId));
        }
    }

    public GuildWarFieldResp() {
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBGuildWar.FIELD_RESP;
    }
}
